﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace Protobuf_Gui.Domain
{
    /// <summary>
    /// rpc Name(InMessage) returns(OutMessage){
    ///     options
    /// }
    /// </summary>
    [Serializable]
    [ContainType(typeof (ServiceMethodOption), "Method option")]
    public class PbServiceMethod : ProtocolElement
    {
        public PbServiceMethod(string name) : base(name)
        {
            MethodOptions = new List<ServiceMethodOption>();
        }

        public PbMessage InMessage { get; set; }

        public PbMessage OutMessage { get; set; }

        public List<ServiceMethodOption> MethodOptions { get; set; }

        public override TreeNode ToTreeNode(TreeNode root)
        {
            throw new NotImplementedException();
        }

        public override void ToFile(TextWriter writer, uint nesting)
        {
            string tabs = Tabs(nesting);
            string first = string.Format("{0}rpc {1}({2}) returns ({3})", tabs, Name, InMessage, OutMessage);
            writer.WriteLine(first);
            writer.WriteLine(tabs + "{");
            foreach (var option in MethodOptions)
            {
                option.ToFile(writer, nesting + 1);
            }
            writer.WriteLine(tabs + "}");
        }
    }
}